package com.cjxy.parking.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cjxy.parking.entity.po.RechargeDetail;
import com.cjxy.parking.entity.query.RechargeDetailQuery;
import com.cjxy.parking.mapper.RechargeDetailMapper;
import com.cjxy.parking.service.RechargeDetailService;
import org.springframework.stereotype.Service;

/**
 * 充值明细 服务层实现类
 *
 * @author: hutao
 * @date: 2025-10-27
 */
@Service
public class RechargeDetailServiceImpl extends ServiceImpl<RechargeDetailMapper, RechargeDetail> implements RechargeDetailService {

    @Override
    public IPage<RechargeDetail> pageRechargeDetail(RechargeDetailQuery rechargeDetailQuery) {
        // 创建分页对象
        IPage<RechargeDetail> page = new Page<>(rechargeDetailQuery.getPagenum(), rechargeDetailQuery.getPageSize());

        // 构建查询条件
        LambdaQueryWrapper<RechargeDetail> queryWrapper = new LambdaQueryWrapper<>();

        // 根据用户名模糊查询
        if (rechargeDetailQuery.getUserName() != null && !rechargeDetailQuery.getUserName().isEmpty()) {
            queryWrapper.like(RechargeDetail::getUserName, rechargeDetailQuery.getUserName());
        }

        // 按创建时间倒序排列
        queryWrapper.orderByDesc(RechargeDetail::getCreateTime);

        return this.page(page, queryWrapper);
    }
}